﻿using EntGuayasSLA.BL;
using EntGuayasSLA.BL.Listas.Criterias;
using Ext.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace EGuayas.Web.Auditoria.Promo.Cumplimiento.tabs
{
    /// <summary>
    /// Summary description for wsGetData
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class wsGetData : System.Web.Services.WebService
    {
      [WebMethod]
      public string GetSubDoc(string id, string table)
        {

            ArchivoSubArchivosCriteria criteria = ArchivoSubArchivosCriteria.NewArchivoSubArchivosCriteria();
            criteria.Id = id;
            criteria.Tabla = table;

            var data = ArchivoLista.GetArchivoLista(criteria);

            if (data.Count != 0)
            {

                GridPanel grid = new GridPanel
                {
                    Height = 90,
                    EnableColumnHide = false,
                    Store = 
                    { 
                        new Store 
                        { 
                            Model = {
                                new Model {
                                    IDProperty = "Id",
                                    Fields = 
                                    {
                                        new ModelField("Id"),
                                        new ModelField("Nombre"),
                                        new ModelField("Descripcion"),
                                        new ModelField("FechaCreacion"),
                                        new ModelField("Version"),
                                        new ModelField("Ruta"),
                                           new ModelField("Comentarios")
                                    }
                                }
                            },
                            DataSource = data
                        }
                    },
                    ColumnModel =
                    {
                        Columns = { }
                    },

                };


                Column addColumn1 = new Column();
                addColumn1.Text = "Nombre";
                addColumn1.DataIndex = "Nombre";
                addColumn1.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn1);

                Column addColumn2 = new Column();
                addColumn2.Text = "Descripción";
                addColumn2.DataIndex = "Descripcion";
                addColumn2.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn2);

                Column addColumn5 = new Column();
                addColumn5.Text = "Comentarios";
                addColumn5.DataIndex = "Comentarios";
                addColumn5.Flex = 4;

                grid.ColumnModel.Columns.Add(addColumn5);

                DateColumn addColumn3 = new DateColumn();
                addColumn3.Text = "Fecha";
                addColumn3.DataIndex = "FechaCreacion";
                addColumn3.Flex = 4;
                addColumn3.Format = "dd-m-yyyy";
                grid.ColumnModel.Columns.Add(addColumn3);

                Column addColumn4 = new Column();
                addColumn4.Text = "Versión";
                addColumn4.DataIndex = "Version";
                addColumn4.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn4);

                CommandColumn commandColumn = new CommandColumn();
                commandColumn.ID = "colAction" + System.Guid.NewGuid();
                commandColumn.Flex = 1;
                //commandColumn.Text = "Visualizar";
                commandColumn.DataIndex = "Id";
                commandColumn.Commands.Add(new GridCommand { Icon = Ext.Net.Icon.Zoom, CommandName = "View", Text = "Vizualizar" });
                commandColumn.Listeners.Command.Handler = "AppGlobalJs.showPdf('../../..',record.data.Ruta);";


                //commandColumn.DirectEvents.Command.Event += GrdSubDoc_Command;
                //commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "Id", Value = "record.data.Id" });
                //commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "command", Value = "command" });
                grid.ColumnModel.Columns.Add(commandColumn);
                return ComponentLoader.ToConfig(grid);
            }
            else
            {
                Panel pnlIfo = new Panel();

                pnlIfo.Html = "<p>Sin versiones</p>";
                pnlIfo.Height = 45;
                return ComponentLoader.ToConfig(pnlIfo);
            }
        }
    }
}
